package com.jiyun.behavior.controller;

import com.BehaviorEntry.ApLikesBehaviorApi;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.behavior.feign.ApCollectionfeginAiticle;
import com.jiyun.behavior.mapper.ApBehaviorEntryMapper;
import com.jiyun.behavior.service.ApLikesBehaviorService;
import com.jiyun.behavior.service.ApReadBehaviorService;
import com.jiyun.behavior.service.ApUnlikesBehaviorSerivce;
import com.jiyun.behavior.service.ipl.ApBehaviorEntryServiceipl;
import com.jiyun.behavior.service.ipl.ApFollowBehaviorServiceipl;
import com.usian.model.atri.CollectionBehaviorDto;
import com.usian.model.behavior.*;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.ws.rs.POST;


@RequestMapping("/behavior/api/v1/behavior")
@RestController
public class ApLikesBehaviorController implements ApLikesBehaviorApi {



    @Autowired
    private ApLikesBehaviorService apLikesBehaviorService;

    @Resource
    private ApFollowBehaviorServiceipl apFollowBehaviorServiceipl;

    @Resource
    private ApReadBehaviorService apReadBehaviorService;

    @Resource
    ApUnlikesBehaviorSerivce apUnlikesBehaviorSerivce;

    @Resource
    ApBehaviorEntryMapper apBehaviorEntryMapper;

    @Resource
    ApCollectionfeginAiticle apCollectionfeginAiticle;

    @PostMapping("saveFollowBehavior")
    @Override
    public ResponseResult saveFollowBehavior(@RequestBody FollowBehaviorDto dto){
        return apFollowBehaviorServiceipl.saveFollowBehavior(dto);
    }

    @PostMapping("yueduxingwei")
    @Override
    public ResponseResult yueduxingwei(@RequestBody ReadBehaviorDto dto){
        return  apReadBehaviorService.yueduxingwei(dto);
    }

    @PostMapping("dianzanxingwei")
    @Override
    public ResponseResult dianzanxingwei(@RequestBody LikesBehaviorDto dto) {
       return apLikesBehaviorService.dianzanxingweitu(dto);
    }

    @PostMapping("buxihuanxingwei")
    @Override
    public ResponseResult buxihuanxingwei(@RequestBody UnLikesBehaviorDto dto) {
        return apUnlikesBehaviorSerivce.buxihuanxingwei(dto);
    }

    @PostMapping("shoucangxingwei")
    @Override
    public ResponseResult shoucangxingwei(@RequestBody CollectionBehaviorDto dto) {
        LambdaQueryWrapper<ApBehaviorEntry> qw=new LambdaQueryWrapper<>();
        qw.eq(ApBehaviorEntry::getEntryId,dto.getEntryId());
        ApBehaviorEntry apBehaviorEntry = apBehaviorEntryMapper.selectOne(qw);
        return apCollectionfeginAiticle.shoucangxingwei(apBehaviorEntry,dto);
    }
}
